<?php
/**
 * @version     $Id$
 * @author      Luu Trong Hieu <tronghieu1012@yahoo.com>
 * @license 	GNU/GPL see license.php
 * @copyright 	Copyright (c) 2010 Luu Trong Hieu. All right reserved.
 */

defined('IN_FLYWHEEL') or die('Restricted Access');

/**
 * Flywheel Date object
 *
 * @package     system
 * @subpackage  datetime
 */
class fDate implements ArrayAccess {
	private $_date = array();
	public function __construct() {}
	
	public function offsetSet($offset, $value) {
		$this->_date[$offset] = $value;				
	}
	
	public function offsetGet($offset) {
		return $this->_date[$offset];
	}
	
	public function offsetUnset($offset) {
		unset($this->_date[$offset]);
	}
	
	public function offsetExists($offset) {
		return isset($this->_date[$offset]);
	}
	
	/**
	 * Return getdate result array {@link http://php.net/manual/en/function.getdate.php}
	 * @param int $time
	 * @param boolean $isGMT, use GMT date
	 * @return array
	 */
	public static function getDateFromTimeStamp($time = null, $isGMT = false) {
		if ($isGMT) {
			$currentTimeZone = date_default_timezone_get();
			date_default_timezone_set('GMT');
			$date = getdate($time);
			date_default_timezone_set($currentTimeZone); //reset default timezone		
		}
		else {
			$date = getdate($time);
		}
		
		return $date;
	}
}